#include "../Customer.h"
#include "AddressService.h"
#include "AddressRepository.h"
#include "../customer/CustomerService.h"
int valieAddress(struct Address* address)
{
    if(address->id==0) return 1;
    if(address->customerId==0) return 1;
    if(CustomerService_isExists(address->customerId)!=0) return 1;
    return 0;
}
int AddressService_create(struct Address* address)
{
    if(valieAddress(address)!=0) return 1;
    AddressRepository_insert(address);
    return 0;
}
int AddressService_modify(struct Address* address)
{
    if(valieAddress(address)!=0) return 1;
    AddressRepository_update(address);
    return 0;
}
int AddressService_remove(long addressId)
{
    AddressRepository_delete(addressId);
    return 0;
}
struct Address* AddressService_load(long addressId)
{
    return AddressRepository_get(addressId);
}
int AddressService_removeByCustomer(long customerId)
{
    AddressRepository_deleteByCustomer(customerId);
    return 0;
}